﻿using System.Data.Entity;

namespace FamilyBook.Repository.EF
{
    public class FamilyBookDbInitializer : IDatabaseInitializer<FamilyBookDbContext>
    {

        public void InitializeDatabase(FamilyBookDbContext context)
        {
            if (!context.Database.Exists() || !context.Database.CompatibleWithModel(true))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.CreateIfNotExists();

                context.Database.ExecuteSqlCommand("CREATE UNIQUE NONCLUSTERED INDEX IX_User_Name ON fb.[User] (Name)");
            }
        }
    }
}
